#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
# @Time   : 2022/3/29 14:59
# @Author : 闫峰
描述: 发送企业微信通知
"""

import requests

from utils.exception.exception import MyCustomException


class WeChatSend:
    """
    企业微信消息通知
    """

    def __init__(self):

        self.headers = {"Content-Type": "application/json"}


    def send_markdown(self, content):
        """
        发送 MarkDown 类型消息
        :param content: 消息内容，markdown形式
        :return:
        """
        _data = {"msgtype": "markdown", "markdown": {"content": content}}
        res = requests.post(url="https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=d1cdd1f3-c9de-477f-b0fb-bc7cd296cd79", json=_data, headers=self.headers)
        if res.json()['errcode'] != 0:
            print(res.json())
            raise MyCustomException("企业微信「MarkDown类型」消息发送失败")



